package org.come.summonequip;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.model.Shop;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.MessagrFlagUntil;
import org.come.until.UserMessUntil;

public class MouseListenerCashRewards implements MouseListener {

    private int index;
    private JpanelCashRewardsMain jpanelCashRewardsMain;

    public MouseListenerCashRewards(int index, JpanelCashRewardsMain jpanelCashRewardsMain) {
        this.index = index;
        this.jpanelCashRewardsMain = jpanelCashRewardsMain;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mousePressed(MouseEvent e) {

        if (jpanelCashRewardsMain.getGoodsType() == 1) {
            if (index > UserMessUntil.getNpcshop().getNpcShopMap().get("600").size()) {
                return;
            }
            jpanelCashRewardsMain.setChooseShop(UserMessUntil.getNpcshop().getNpcShopMap().get("600").get(index));
            if (jpanelCashRewardsMain.getChooseShop() != null) {
                jpanelCashRewardsMain.getChooseGoods().setIcon(
                        GoodsListFromServerUntil.imgpathAdaptive(jpanelCashRewardsMain.getChooseShop().getShopskin(),
                                55, 53));
            }
        } else if (jpanelCashRewardsMain.getGoodsType() == 2) {
            if (index > UserMessUntil.getNpcshop().getNpcShopMap().get("601").size()) {
                return;
            }
            jpanelCashRewardsMain.setChooseShop(UserMessUntil.getNpcshop().getNpcShopMap().get("601").get(index));
            if (jpanelCashRewardsMain.getChooseShop() != null) {
                jpanelCashRewardsMain.getChooseGoods().setIcon(
                        GoodsListFromServerUntil.imgpathAdaptive(jpanelCashRewardsMain.getChooseShop().getShopskin(),
                                55, 53));
            }
        }else if (jpanelCashRewardsMain.getGoodsType() == 3) {
            if (index > UserMessUntil.getNpcshop().getNpcShopMap().get("602").size()) {
                return;
            }
            jpanelCashRewardsMain.setChooseShop(UserMessUntil.getNpcshop().getNpcShopMap().get("602").get(index));
            if (jpanelCashRewardsMain.getChooseShop() != null) {
                jpanelCashRewardsMain.getChooseGoods().setIcon(
                        GoodsListFromServerUntil.imgpathAdaptive(jpanelCashRewardsMain.getChooseShop().getShopskin(),
                                55, 53));
            }
        }
                jpanelCashRewardsMain.getTextNum().setText("1");

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE1)) {
            MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
        }
        // TODO Auto-generated method stub鼠标移入
        List<Shop> shopList = null;
        if (jpanelCashRewardsMain.getGoodsType() == 1) {
            shopList = UserMessUntil.getNpcshop().getNpcShopMap().get("600");
        } else if (jpanelCashRewardsMain.getGoodsType() == 2) {
            shopList = UserMessUntil.getNpcshop().getNpcShopMap().get("601");
        } else if (jpanelCashRewardsMain.getGoodsType() == 3) {
            shopList = UserMessUntil.getNpcshop().getNpcShopMap().get("602");
        }
        if (shopList == null) {
            return;
        }
        if (index >= shopList.size()) {
            return;
        }
        Shop shop = shopList.get(index);
        if (shop != null) {
//            String text = shop.getShoptext();
//            String value = null;
            Goodstable goodstable = UserMessUntil.getgoodstable(shop.getShopiid());
            if (goodstable != null && goodstable.getType() == 112) {
//                value = goodstable.getValue();
                shop.setQualiy(goodstable.getQuality());
                shop.setValue(goodstable.getValue());
            }
            ZhuFrame.getZhuJpanel().creatgoodtext(shop);
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE12)) {
            MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
        }
        // TODO Auto-generated method stub鼠标离开
        ZhuFrame.getZhuJpanel().cleargoodtext();
    }

}
